package com.tianfei.crowd.controller;


import com.tianfei.crowd.entity.po.AddressPO;
import com.tianfei.crowd.entity.vo.AddressVO;
import com.tianfei.crowd.entity.vo.OrderProjectVO;
import com.tianfei.crowd.entity.vo.OrderVO;
import com.tianfei.crowd.service.api.OrderService;
import com.tianfei.crowd.utils.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Herz
 * @date: 2021/8/9 19:31
 */
@RestController
public class OrderProviderController {

    @Autowired
    private OrderService orderService;


    @RequestMapping("/save/order/vo/remote")
    ResultEntity<String> saveOrderVORemote(@RequestBody OrderVO orderVO) {

        try {
            orderService.saveOrder(orderVO);

            return ResultEntity.successWithOutData();
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }
    }


    @RequestMapping("/save/address/vo/remote")
    ResultEntity<String> saveAddressVORemote(@RequestBody AddressVO addressVO){

        try {
            orderService.saveAddressVO(addressVO);

            return ResultEntity.successWithOutData();
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }
    }


    @RequestMapping("/get/address/vo/remote")
    ResultEntity<List<AddressVO>> getAddressVORemote(@RequestParam("memberId") Integer memberId){

        try {
            List<AddressVO> addressVOList = orderService.selectAddressVO(memberId);

            return ResultEntity.successWithData(addressVOList);
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }
    }


    @RequestMapping("/get/order/project/vo/remote")
    ResultEntity<OrderProjectVO> getOrderProjectVORemote(
            @RequestParam("returnId") Integer returnId){

        try {
            OrderProjectVO orderProjectVO =  orderService.selectOrderProjectVO(returnId);

            return ResultEntity.successWithData(orderProjectVO);
        } catch (Exception e) {
            e.printStackTrace();

            return ResultEntity.failed(e.getMessage());
        }
    }
}
